package com.xiumu.service.sys.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiumu.dao.sys.DictItemDao;
import com.xiumu.pojo.sys.entity.DictItem;
import com.xiumu.service.sys.DictItemService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 字典项
 *
 * @author XiuMu
 * @since 2024/12/30 21:14
 */
@Service
public class DictItemServiceImpl extends ServiceImpl<DictItemDao, DictItem> implements DictItemService {

    @Override
    public List<DictItem> listByDictIdOrDictCode(Long dictId, String dictCode) {
        return list(Wrappers.lambdaQuery(DictItem.class)
                .eq(Objects.nonNull(dictId), DictItem::getDictId, dictId)
                .eq(StrUtil.isNotBlank(dictCode), DictItem::getDictCode, dictCode));
    }

    @Override
    public Boolean existByDictIdAndValue(Long id, String value) {
        return this.exists(Wrappers.lambdaQuery(DictItem.class).eq(DictItem::getDictId, id).eq(DictItem::getValue, value));
    }
}

